[iOS] becomeFirstResponder: automatically scroll to the UIControl that becomes first responder

Posted by Manni on Stack Overflow See other posts from Stack Overflow or by Manni
Published on 2011-02-18T15:07:35Z Indexed on 2011/02/18 15:25 UTC
Read the original article Hit count: 328

I have a grouped UITableViewController with one section and many rows. Each cell consists of two elements: a UILabel with a description and a UITextField for an input. A form, I would say.

On the bottom is a button "Next" the go to the next view. But before that, I validate the UITextField's: if the user hasn't filled a field, this field should get the focus, so that the user sees that he needs to enter something. I tried with this:

[inputField becomeFirstResponder];

Remember, the button I pressed is on the bottom of my view and imagine that the UITextField is on the top. In this situation, the field doesn't get the focus because it is too far away. Now when I scroll up slowly and the field gets visible, the field becomes first responder and gets the cursor :-) Conclusion: The becomeFirstResponder worked, but does not exactly do what I wanted to. I don't want to scroll up with my finger, the field should get the focus and visible automatically.

Is there any way to "jump" directly to my field? Use an alternative to becomeFirstResponder? Scroll to my field automatically?

Thanks for your help!

© Stack Overflow or respective owner

Related posts about iphone

Related posts about ios